﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net; 
 using System.Net.Http; 
 using System.Web.Http; 
 using DotNetNuke.Entities.Portals; 
 using DotNetNuke.Entities.Users; 
 using DotNetNuke.Security.Roles;
using DotNetNuke.Web.Api;

namespace SPA_Gallery
{
    public class GalleryController:DotNetNuke.Web.Api.DnnApiController
    {

        [AllowAnonymous,ValidateAntiForgeryToken,HttpPost]
        public System.Net.Http.HttpResponseMessage GetGalleries(paramGalleries parameters)
        {

            List<Components.GalleryEntity> toReturn = new Components.GalleryDNNFileController(this.PortalSettings.PortalId,this.ActiveModule.ModuleID).GetGalleries(parameters.GalleryId);
            
            /*= new List<Components.GalleryEntity>();
            toReturn.Add(new Components.GalleryEntity() { GalleryId="/1&", GalleryName="Ma gallery", ParentId="" });
            toReturn.Add(new Components.GalleryEntity() { GalleryId = "2", GalleryName = "Ma gallery2", ParentId = "" });*/
            return Request.CreateResponse(HttpStatusCode.OK,toReturn);
        }
          [AllowAnonymous, ValidateAntiForgeryToken, HttpPost]
        public System.Net.Http.HttpResponseMessage GetGallery(paramGalleries parameters)
        {
            Components.GalleryEntity toReturn = new Components.GalleryDNNFileController(this.PortalSettings.PortalId, this.ActiveModule.ModuleID).GetGallery(parameters.GalleryId);
            return Request.CreateResponse(HttpStatusCode.OK, toReturn);
        }
        [AllowAnonymous, ValidateAntiForgeryToken,HttpPost]
        public System.Net.Http.HttpResponseMessage GetImages(paramGalleries parameters)
        {
            List<Components.ImageEntity> toReturn =  new Components.GalleryDNNFileController(this.PortalSettings.PortalId,this.ActiveModule.ModuleID).GetImages(parameters.GalleryId); /*new List<Components.ImageEntity>();
            toReturn.Add(new Components.ImageEntity() { GalleryId = "", FileName="Picture1", FullUrl="http://fullurl", ThumbUrl="http://thumbUrl", ImageId="1"});*/
            return Request.CreateResponse(HttpStatusCode.OK, toReturn);
        }
        [AllowAnonymous, ValidateAntiForgeryToken, HttpPost]
        public System.Net.Http.HttpResponseMessage GetImage(paramImage parameters)
        {
            Components.ImageEntity toReturn = new Components.GalleryDNNFileController(this.PortalSettings.PortalId, this.ActiveModule.ModuleID).GetImage(parameters.ImageId); /*new List<Components.ImageEntity>();
            toReturn.Add(new Components.ImageEntity() { GalleryId = "", FileName="Picture1", FullUrl="http://fullurl", ThumbUrl="http://thumbUrl", ImageId="1"});*/
            return Request.CreateResponse(HttpStatusCode.OK, toReturn);
        }

        [ValidateAntiForgeryToken, HttpPost]
        public System.Net.Http.HttpResponseMessage SetImage(contextImage parameters)
        {
            Components.ImageEntity toReturn=parameters.currentImage;
            //Update the image

            return Request.CreateResponse(HttpStatusCode.OK, toReturn);
        }
        [AllowAnonymous, ValidateAntiForgeryToken, HttpPost]
        public System.Net.Http.HttpResponseMessage AddGallery(addParamGalleries parameters)
        {
            int toReturn = -1;
          toReturn=  new Components.GalleryDNNFileController(this.PortalSettings.PortalId, this.ActiveModule.ModuleID).AddGallery(parameters.ParentGalleryId, parameters.GalleryName);
            return Request.CreateResponse(HttpStatusCode.OK, toReturn);
        }

        public class addParamGalleries
        {
            public string ParentGalleryId { get; set; }
            public string GalleryName { get; set; }
        }
        public class paramGalleries
        {
            public string GalleryId { get; set; }
            public int PageSize { get; set; }
            
        }
        public class paramImage
        {
            public string ImageId { get; set; }
        }
        public class contextImage {
            public paramGalleries currentGallery { get; set; }
            public SPA_Gallery.Components.ImageEntity currentImage { get; set; }

        }
    }
}